﻿using System;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace Kugar.Tool.RemoteEventBus.Triggers
{
    public interface ISyncEventTrigger<in T>:IEventTrigger  //where T : EventArgs
    {
        /// <summary>
        /// 触发事件,并返回所有接收者返回的数据
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <returns></returns>
        JObject[] Trigger(T eventArgs);

        /// <summary>
        /// 触发事件,并返回所有接收者返回的数据
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <param name="isThrowErrorWhenTimeout">当远程调用出现timeout的时候,是否要抛出timeout错误,如果为false,则返回已接收到的数值,不抛出错误,,,默认为true</param>
        /// <returns></returns>
        JObject[] Trigger(T eventArgs, int timeout, bool isThrowErrorWhenTimeout);

        /// <summary>
        /// 触发事件,并返回所有接收者返回的数据
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <returns></returns>
        Task<JObject[]> TriggerAsync(T eventArgs);

        /// <summary>
        /// 触发事件,并返回所有接收者返回的数据
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <param name="isThrowErrorWhenTimeout">当远程调用出现timeout的时候,是否要抛出timeout错误,如果为false,则返回已接收到的数值,不抛出错误,,,默认为true</param>
        /// <returns></returns>
        Task<JObject[]> TriggerAsync(T eventArgs, int timeout, bool isThrowErrorWhenTimeout);

        ///// <summary>
        ///// 触发一个事件,并且只获取第一个返回的值,并抛掉其他值
        ///// </summary>
        ///// <param name="eventArgs"></param>
        ///// <param name="timeout"></param>
        ///// <returns></returns>
        //JObject TriggerWithFirstResult(T eventArgs, int timeout = 15000);

        /// <summary>
        /// 触发事件并发送给指定ID的订阅者,该功能用于补发事件
        /// </summary>
        /// <param name="eventArgs">调用的参数</param>
        /// <param name="clientID">接收者ID</param>
        /// <returns></returns>
        JObject[] TriggerToClientID(string clientID, T eventArgs);

        /// <summary>
        /// 触发事件并发送给指定ID的订阅者,该功能用于补发事件
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <param name="clientID"></param>
        /// <returns></returns>
        Task<JObject[]> TriggerToClientIDAsync(string clientID, T eventArgs);
        

    }
} 
